package com.fcscs.cservice.ws.endpoint;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;

import com.fcscs.cservice.ws.schema.dndservice.GetDndRequest;
import com.fcscs.cservice.ws.schema.dndservice.GetDndResponse;
import com.fcscs.cservice.ws.schema.dndservice.SetDndRequest;
import com.fcscs.cservice.ws.schema.dndservice.SetDndResponse;
import com.fcscs.ecms.service.ECMSDndManager;

/**
 * @author pvttinh
 * 
 */

@Endpoint
public class DndServiceEndpoint {

	@Autowired
	private ECMSDndManager dndMgr;
	
	/**
	 * 
	 * @param req
	 * @return
	 */
	@PayloadRoot(localPart = CServiceWSConstants.GET_DND_RQ, namespace = CServiceWSConstants.DND_SERVICE_NAMESPACE_URI)
	@ResponsePayload
	public GetDndResponse getDnd(@RequestPayload GetDndRequest req) {

		GetDndResponse resp = new GetDndResponse();
		try{
			resp.setDndInfo(this.dndMgr.getDndInfo(req.getOrgId(), req.getPropId(), req.getGuestProfileId(), req.getReservationId()));
			resp.setSuccess(true);
		}catch (Exception e) {
			// TODO: handle exception
			resp.setSuccess(false);
			resp.setErrorMessage(e.getMessage());
		}
		
		return resp;
	}
	
	@PayloadRoot(localPart = CServiceWSConstants.SET_DND_RQ, namespace = CServiceWSConstants.DND_SERVICE_NAMESPACE_URI)
	@ResponsePayload
	public SetDndResponse setDnd(@RequestPayload SetDndRequest req) {

		SetDndResponse resp = new SetDndResponse();
		try{
			resp.setDndInfo(this.dndMgr.setDndInfo(req.getDndInfo(), req.getFcsUserId()));
			resp.setSuccess(true);
		}catch (Exception e) {
			// TODO: handle exception
			resp.setSuccess(false);
			resp.setErrorMessage(e.getMessage());
		}
		
		return resp;
	}
}
